/**
 * Created by ayu on 2017/6/26.
 */
const request = require ('request');
let logger = require ('../utils/logger/Logger');
const wechatConfig = require ('../../resources/WechatAppConfig');
const accessTokenController = require ('../controllers/AccessTokenController');
let menuInfo = {
    'button': [
        {
            'type'      : 'view',
            'name'      : '影院',
            'sub_button': [
                {
                    'type': 'view',
                    'name': '影院',
                    'url': `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${wechatConfig.app.appid}&redirect_uri=http%3A%2F%2F${wechatConfig.dev_url}%2Fcinema&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
                    // 'url' : 'http://www.baidu.com'
                },
                {
                    'type': 'view',
                    'name': '影片查询',
                    // 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2FpageHome&response_type=code&scope=snsapi_base&state=123#wechat_redirect'
                    'url' : 'http://www.baidu.com'
                }
            ]
        },
        {
            'type': 'view',
            'name': '观影',
            // 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Fscan&response_type=code&scope=snsapi_base&state=123#wechat_redirect'
            'url' : 'http://www.baidu.com'
        },
        {
            'type'      : 'view',
            'name'      : '我',
            'sub_button': [
                {
                    'type': 'view',
                    'name': '个人信息',
                    // 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Fmemberhome&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect'
                    'url' : 'http://www.baidu.com'
                },
                {
                    'type': 'view',
                    'name': '我要开影院',
                    // 'url': 'http://mp.weixin.qq.com/s/cMnVAYZr7z66yp9QnSuHfw'
                    'url' : 'http://www.baidu.com'
                }
            ]
        }
    ]
};
module.exports =
    {
        addMenu: function ()
        {
            const accessToken = accessTokenController.getAccessToken ();
            request ({
                url   : `${wechatConfig.menuUrl.addMenuUrl}${accessToken}`,
                method: 'POST',
                json  : menuInfo
            }, function ( err, response, body )
            {
                if (err)
                {
                    logger.error ('自定义菜单创建失败', err);
                    return;
                }
                console.log ('自定义菜单创建成功', body);
            });
        }
    };
